package atom.loader.types {
	
	import atom.loader.core.AbstractLoader;
	import atom.loader.types.AssetLoader;
	import atom.loader.ILoader;
	import atom.loader.IAsset;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	
	/**
	 * ...
	 * @author Jorge Braccini
	 */
	public class AssetMultimedia extends AssetLoader implements ILoader, IAsset {
		
		private var _loader:Loader;
		
		public function AssetMultimedia(id:String, url:String = null) {
			super(id, url);
			init();
		}
		
		/* INTERFACE ar.com.jbraccini.loader.ILoader */
		
		override public function load():void {
			_loader.load(_url);
		}
		
		override public function cancel():void {
			_loader.close();
		}
		
		override public function reload():void {
			_loader.load(_url);
		}
		
		
		
		/* INTERFACE ar.com.jbraccini.loader.IAsset */
		
		override public function get content():* { 
			return _loader.content; 
		}
		
		override public function get contentType():String { return AssetTypes.MULTIMEDIA; }
		
		
		
		/* INTERFACE ar.com.jbraccini.IDestroyable */
		
		override public function destroy():void {
			cancel();
			clean();
			init();
		}
		
		
		
		///////////////////////////////////////////////////////////////
		// Private Methods ////////////////////////////////////////////
		///////////////////////////////////////////////////////////////
		
		override protected function init():void {
			super.init();
			
			_loader = new Loader();
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, 			redispatch);
			_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, 	redispatch);
			_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, 	redispatch);
			_loader.contentLoaderInfo.addEventListener(Event.INIT, 				redispatch);
		}
		
		private function clean():void {
			_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, 			redispatch);
			_loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, 	redispatch);
			_loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, 	redispatch);
			_loader.contentLoaderInfo.removeEventListener(Event.INIT, 				redispatch);
		}
		
		
		// Event Handlers /////////////////////////////////////////////
		
		
	}

}